﻿Public Class Frm_LoCarsManagement
    Implements IDServer.IDServer.IDServer
    Private WithEvents MainFrom As Frm_MainForm
    Private mtableQ As New DataTable
    Private mtable As New DataTable
    Private RSTcmb As New DataSet
    Private RST As New DataSet
    Private RSTArranged As New DataSet
    Private FillDetailRST As New DataSet

    Public Property SelectObject() As Frm_MainForm
        Get
            Return MainFrom
        End Get
        Set(ByVal value As Frm_MainForm)
            MainFrom = value
        End Set
    End Property

#Region "Sub and Function"

    Private Function ConditonToSave() As String
        Try
            Dim B As Boolean = True
            If Me.TxtArrangedBill.Text = "" Then
                B = False
            End If
            Return B
        Catch ex As Exception

        End Try
    End Function

    Private Sub BtnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFind.Click
        Try
            Dim strsql As String = ""
            Dim fInstructionStartDate As String = Me.DtpStartDate.Value
            Dim fInstructionEndDate As String = Me.DtpEndDate.Value
            strsql = "select fInstructions,fInstructionDate,fInstructionTYPE,fItem,fContract,fIsNeedTran,fstartstation,fEndStation,fGoodsCubage,fGoodsWeight,fNumArranged='',fNameArranged='',TimeArraged='',fID='',fName='' from dbo.LO_Instructions where fInstructionDate between '" & fInstructionStartDate & "' and '" & fInstructionEndDate & "' and fIsNeedTran=1 and fInstructions not in (select fInstructions from LO_TransportArrangedB)"
            RST = ReturnDataset(strsql)
            Me.DGVTranArrangeDetail.DataSource = RST.Tables(0)

        Catch ex As Exception

        End Try
    End Sub

    Private Sub Frm_LoCarsManagement_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Me.TxtArrangedBill.Enabled = False
            Me.DtpStartDate.Enabled = False
            Me.DtpEndDate.Enabled = False

            Me.CmbTranArranged.Visible = False
            Me.MaskTxtStartTime.Visible = False
            Me.CmbDriver.Visible = False
            BindDGVTranArrangeMasterQ()
            BindDGVTranArrangeDetail()
            LoadComb()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub DGVTranArrangeDetail_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVTranArrangeDetail.CellClick
        Try
            If Me.DGVTranArrangeDetail.CurrentCell.ColumnIndex = 10 Then
                Me.CmbTranArranged.Visible = True

                Dim Rect As Rectangle = Me.DGVTranArrangeDetail.GetCellDisplayRectangle(Me.DGVTranArrangeDetail.CurrentCell.ColumnIndex, Me.DGVTranArrangeDetail.CurrentCell.RowIndex, False)
                Me.CmbTranArranged.Left = Rect.Left
                Me.CmbTranArranged.Top = Rect.Top
                Me.CmbTranArranged.Width = Rect.Width
                Me.CmbTranArranged.Height = Rect.Height
            End If

            If Me.DGVTranArrangeDetail.CurrentCell.ColumnIndex = 12 Then
                Me.MaskTxtStartTime.Visible = True
                Dim Rect1 As Rectangle = Me.DGVTranArrangeDetail.GetCellDisplayRectangle(Me.DGVTranArrangeDetail.CurrentCell.ColumnIndex, Me.DGVTranArrangeDetail.CurrentCell.RowIndex, False)
                Me.MaskTxtStartTime.Left = Rect1.Left
                Me.MaskTxtStartTime.Top = Rect1.Top
                Me.MaskTxtStartTime.Width = Rect1.Width
                Me.MaskTxtStartTime.Height = Rect1.Height

            End If

            If Me.DGVTranArrangeDetail.CurrentCell.ColumnIndex = 13 Then
                Me.CmbDriver.Visible = True
                Dim Rect2 As Rectangle = Me.DGVTranArrangeDetail.GetCellDisplayRectangle(Me.DGVTranArrangeDetail.CurrentCell.ColumnIndex, Me.DGVTranArrangeDetail.CurrentCell.RowIndex, False)
                Me.CmbDriver.Left = Rect2.Left
                Me.CmbDriver.Top = Rect2.Top
                Me.CmbDriver.Width = Rect2.Width
                Me.CmbDriver.Height = Rect2.Height
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub CmbTranArranged_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmbTranArranged.Click
        Try
        Catch ex As Exception
        End Try
    End Sub

    Private Sub CmbTranArranged_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmbTranArranged.SelectedIndexChanged
        Try
            If Me.DGVTranArrangeDetail.Rows.Count > 1 Then
                Me.DGVTranArrangeDetail.CurrentRow.Cells("fNumArranged").Value = Me.CmbTranArranged.SelectedValue
                Me.DGVTranArrangeDetail.CurrentRow.Cells("fNameArranged").Value = Me.CmbTranArranged.Text
                Me.CmbTranArranged.Visible = False
            End If
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub

    Private Sub DGVTranArrangeDetail_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles DGVTranArrangeDetail.Scroll
        Try
            Me.CmbTranArranged.Visible = False
            Me.MaskTxtStartTime.Visible = False
            Me.CmbDriver.Visible = False
        Catch ex As Exception

        End Try
    End Sub

    Private Sub MaskTxtStartTime_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MaskTxtStartTime.LostFocus
        Try
            Me.DGVTranArrangeDetail.CurrentRow.Cells("TimeArraged").Value = Me.MaskTxtStartTime.Text
            Me.MaskTxtStartTime.Visible = False
        Catch ex As Exception

        End Try
    End Sub

    Private Sub CmbDriver_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmbDriver.SelectedIndexChanged
        Try
            Me.DGVTranArrangeDetail.CurrentRow.Cells("fID").Value = Me.CmbDriver.SelectedValue
            Me.DGVTranArrangeDetail.CurrentRow.Cells("fName").Value = Me.CmbDriver.Text
            Me.CmbDriver.Visible = False

        Catch ex As Exception

        End Try
    End Sub

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DtpInstructionDate.ValueChanged

    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtCardNoQ.TextChanged

    End Sub

    Private Sub ContextMenuStrip1_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening

    End Sub

    Private Sub InsertToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InsertToolStripMenuItem.Click
        Try
            'Me.DGVTranArrangeDetail.Rows.Insert(Me.DGVTranArrangeDetail.CurrentRow.Index - 1, 1)
            Dim Rowindex As Integer = Me.DGVTranArrangeDetail.CurrentRow.Index
            Dim NewRow As DataRow = RST.Tables(0).NewRow

            NewRow("fInstructions") = Me.DGVTranArrangeDetail.CurrentRow.Cells("fInstructions").Value
            NewRow("fInstructionDate") = Me.DGVTranArrangeDetail.CurrentRow.Cells("fInstructionDate").Value
            NewRow("fInstructionTYPE") = Me.DGVTranArrangeDetail.CurrentRow.Cells("fInstructionTYPE").Value
            NewRow("fItem") = Me.DGVTranArrangeDetail.CurrentRow.Cells("fItem").Value
            NewRow("fContract") = Me.DGVTranArrangeDetail.CurrentRow.Cells("fContract").Value
            NewRow("fIsNeedTran") = Me.DGVTranArrangeDetail.CurrentRow.Cells("fIsNeedTran").Value
            NewRow("fstartstation") = Me.DGVTranArrangeDetail.CurrentRow.Cells("fstartstation").Value
            NewRow("fEndStation") = Me.DGVTranArrangeDetail.CurrentRow.Cells("fEndStation").Value
            NewRow("fGoodsCubage") = Me.DGVTranArrangeDetail.CurrentRow.Cells("fGoodsCubage").Value
            NewRow("fGoodsWeight") = Me.DGVTranArrangeDetail.CurrentRow.Cells("fGoodsWeight").Value

            RST.Tables(0).Rows.InsertAt(NewRow, Rowindex + 1)
            RST.AcceptChanges()
            Me.DGVTranArrangeDetail.DataSource = RST.Tables(0)
        Catch ex As Exception
            MessageBox.Show(ex.ToString)

        End Try
    End Sub

    Private Sub BtnFindArranged_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFindArranged.Click
        Try
            Dim StrSQL As String = ""
            Dim QueryRST As New DataSet
            Dim fTranArrangedBill As String = Me.TxtBillArrangedQ.Text.ToString.Trim
            Dim fInstructions As String = Me.TxtInstructionQ.Text.ToString.Trim
            Dim fInstructionDate As String = Me.DtpInstructionDate.Text.ToString.Trim
            Dim fInstructionType As String = Me.CmbInstructionTypeQ.SelectedValue
            Dim fNumArranged As String = Me.TxtCardNoQ.Text.ToString.Trim
            Dim fID As String = Me.TxtDriverQ.Text
            Dim fTranArrangedBy As String = Me.TxtArrangedBy.Text
            Dim fTranArrangedDate As String = FormatDate(Me.DTPArrangedDateQ.Text.ToString.Trim)


            StrSQL = "SELECT a.fTranArrangedBill,a.fTranArrangedBy,a.fTranArrangedDate,b.fInstructions,c.fInstructionDate,fInstructionType,b.fNumArranged,b.fNameArranged,b.fID,a.fBillStatus  FROM LO_TransportArrangedA  a,LO_TransportArrangedB b,LO_Instructions c "
            StrSQL = StrSQL & "where  a.fTranArrangedBill=b.fTranArrangedBill and  b.fInstructions=c.fInstructions"
            If TxtBillArrangedQ.Text.Length > 0 Then
                StrSQL = StrSQL & " and a.fTranArrangedBill='" & fTranArrangedBill & "'"
            End If
            If TxtInstructionQ.Text.Length > 0 Then
                StrSQL = StrSQL & " and b.fInstructions='" & fInstructions & "'"
            End If
            If DtpInstructionDate.Checked = True Then
                StrSQL = StrSQL & " and c.fInstructionDate='" & fInstructionDate & "'"
            End If

            StrSQL = StrSQL & " and c.fInstructionType='" & fInstructionType & "'"

            If TxtCardNoQ.Text.Length > 0 Then
                StrSQL = StrSQL & " and b.fNumArranged='" & fNumArranged & "'"
            End If
            If TxtDriverQ.Text.Length > 0 Then
                StrSQL = StrSQL & " and b.fID='" & fID & "'"
            End If
            If TxtArrangedBy.Text.Length > 0 Then
                StrSQL = StrSQL & " and a.fTranArrangedBy='" & fTranArrangedBy & "'"
            End If
            If DTPArrangedDateQ.Checked = True Then
                StrSQL = StrSQL & " and a.fTranArrangedDate='" & fTranArrangedDate & "'"
            End If
            QueryRST = ReturnDataset(StrSQL)
            Me.DGVTranArrangeMasterQ.DataSource = QueryRST.Tables(0)

            If QueryRST.Tables(0).Rows.Count > 0 Then
                MainFrom.ToolStripEdit.Enabled = True
                MainFrom.ToolStripDelete.Enabled = True
            End If

        Catch ex As Exception

        End Try
    End Sub

    Private Sub DGVTranArrangeMasterQ_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVTranArrangeMasterQ.CellDoubleClick
        Try
            Me.DGVTranArrangeMaster.SelectedIndex = 1
            Dim CurrentArrangedBill As String = Me.DGVTranArrangeMasterQ.CurrentRow.Cells("fTranArrangedBill").Value
            Me.TxtArrangedBill.Text = CurrentArrangedBill

            Dim sql As String = "select a.fInstructions,a.fInstructionDate,a.fInstructionTYPE,a.fItem,a.fContract,a.fIsNeedTran,a.fstartstation,a.fEndStation,a.fGoodsCubage,a.fGoodsWeight,b.fNumArranged,b.fNameArranged,b.fTimeArranged,b.fID,fName='' from dbo.LO_Instructions a,LO_TransportArrangedB b where a.finstructions=b.finstructions and b.fTranArrangedBILL='" & CurrentArrangedBill & "'"

            RST = ReturnDataset(sql)
            Me.DGVTranArrangeDetail.DataSource = RST.Tables(0)

        Catch ex As Exception

        End Try
    End Sub

#End Region

#Region "BindCaptionStr"

    Private Function BindHast(ByVal index As Integer) As Hashtable
        Try
            Dim mTable As New Hashtable
            With mTable
                Select Case index
                    Case 0
                        .Add("fTranArrangedBill", "調配單")
                        .Add("fTranArrangedBy", "調配員")
                        .Add("fTranArrangedDate", "調配日期")
                        .Add("fInstructions", "指令")
                        .Add("fInstructionDate", "指令日期")
                        .Add("fInstructionTYPE", "指令類型")
                        .Add("fNumArranged", "Card No")
                        .Add("fNameArranged", "名稱")
                        .Add("fTimeArranged", "時間安排")
                        .Add("fID", "司機編號")
                        .Add("fBillStatus", "調配單狀態")
                    Case 1
                        .Add("fInstructions", "指令")
                        .Add("fInstructionDate", "指令日期")
                        .Add("fInstructionTYPE", "指令類型")
                        .Add("fItem", "項目編號")
                        .Add("fContract", "合同編號")
                        .Add("fIsNeedTran", "需要運輸")
                        .Add("fstartstation", "起始站")
                        .Add("fEndStation", "終點站")
                        .Add("fGoodsCubage", "貨物縂體積")
                        .Add("fGoodsWeight", "貨物縂重量")
                        .Add("fNumArranged", "Card No")
                        .Add("fNameArranged", "名稱")
                        .Add("fTimeArranged", "時間安排")
                        .Add("fID", "司機編號")
                        .Add("fName", "司機")

                End Select
            End With
            Return mTable
        Catch ex As Exception

        End Try
    End Function

    Private Sub BindDGVTranArrangeMasterQ()
        Try
            mtableQ = New DataTable
            With mtableQ.Columns
                .Add("fTranArrangedBill")
                .Add("fTranArrangedBy")
                .Add("fTranArrangedDate")
                .Add("fInstructions")
                .Add("fInstructionDate")
                .Add("fInstructionTYPE")
                .Add("fNumArranged")
                .Add("fNameArranged")
                .Add("fTimeArranged")
                .Add("fID")
                .Add("fBillStatus")
            End With

            Me.DGVTranArrangeMasterQ.DataSource = mtableQ

            With Me.DGVTranArrangeMasterQ
                For i As Integer = 0 To Me.DGVTranArrangeMasterQ.Columns.Count - 1
                    Dim mKey As String = .Columns(i).Name
                    Dim CaptionStr As String = BindHast(0).Item(mKey)
                    .Columns(i).HeaderText = CaptionStr
                Next
            End With

        Catch ex As Exception

        End Try
    End Sub
    Private Sub BindDGVTranArrangeDetail()
        Try
            mtable = New DataTable
            With mtable.Columns
                .Add("fInstructions")
                .Add("fInstructionDate")
                .Add("fInstructionTYPE")
                .Add("fItem")
                .Add("fContract")
                .Add("fIsNeedTran")
                .Add("fstartstation")
                .Add("fEndStation")
                .Add("fGoodsCubage")
                .Add("fGoodsWeight")
                .Add("fNumArranged")
                .Add("fNameArranged")
                .Add("fTimeArranged")
                .Add("fID")
                .Add("fName")
            End With
            Me.DGVTranArrangeDetail.DataSource = mtable

            With Me.DGVTranArrangeDetail
                For i As Integer = 0 To Me.DGVTranArrangeDetail.Columns.Count - 1
                    Dim mKey As String = .Columns(i).Name
                    Dim CaptionStr As String = BindHast(1).Item(mKey)
                    .Columns(i).HeaderText = CaptionStr
                Next
                .Columns(10).DefaultCellStyle.BackColor = Color.AliceBlue
                .Columns(12).DefaultCellStyle.BackColor = Color.AliceBlue
                .Columns(13).DefaultCellStyle.BackColor = Color.AliceBlue
            End With
        Catch ex As Exception

        End Try
    End Sub

    Private Sub LoadComb()
        Try
            Dim StrSql As String = ""
            RSTcmb = New DataSet
            StrSql = "select * from Lo_TransportCars;"
            StrSql = StrSql & "select * from BSC_Driver;"
            StrSql = StrSql & "select * from dbo.BSC_OtherDefineA a, BSC_OtherDefineb b where a.id=b.itemno and a.id=78"
            RSTcmb = ReturnDataset(StrSql)

            With CmbTranArranged
                .DataSource = RSTcmb.Tables(0)
                .DisplayMember = "fTruckName"
                .ValueMember = "fTruckID"
            End With

            With Me.CmbDriver
                .DataSource = RSTcmb.Tables(1)
                .DisplayMember = "fName"
                .ValueMember = "fID"
            End With

            With Me.CmbInstructionTypeQ
                .DataSource = RSTcmb.Tables(2)
                .DisplayMember = "ListA"
                .ValueMember = "ListCode"
            End With
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub

#End Region

#Region "Interface"

    Public Function ActionAdd() As Boolean Implements IDServer.IDServer.IDServer.ActionAdd
        Try
            If AddEnable = False Then
                MessageBox.Show("對不起，您沒有新增權限", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If

            Me.DGVTranArrangeMaster.SelectedIndex = 1
            With MainFrom
                .ToolStripAdd.Enabled = False
                .ToolStripEdit.Enabled = False
                .ToolStripDelete.Enabled = False
                .ToolStripCancel.Enabled = True
                .ToolStripSave.Enabled = True
            End With
            Me.TxtArrangedBill.Enabled = True
            Me.DtpStartDate.Enabled = True
            Me.DtpEndDate.Enabled = True
            Me.BtnFind.Enabled = True
            Me.TxtArrangedBill.Text = ""

            Me.DGVTranArrangeDetail.DataSource = mtable

        Catch ex As Exception

        End Try
    End Function

    Public Function ActionCancel() As Boolean Implements IDServer.IDServer.IDServer.ActionCancel
        Try
            With MainFrom
                .ToolStripAdd.Enabled = True
                .ToolStripSave.Enabled = False
                .ToolStripCancel.Enabled = False
            End With
            Me.TxtArrangedBill.Enabled = False
            Me.DtpStartDate.Enabled = False
            Me.DtpEndDate.Enabled = False
            Me.BtnFind.Enabled = False

        Catch ex As Exception

        End Try
    End Function

    Public Function ActionDelete() As Boolean Implements IDServer.IDServer.IDServer.ActionDelete
        If DeleteEnable = False Then
            MessageBox.Show("對不起，您沒有刪除權限", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Function
        End If

    End Function

    Public Function ActionEdit() As Boolean Implements IDServer.IDServer.IDServer.ActionEdit
        Try
            If EditEnable = False Then
                MessageBox.Show("對不起，您沒有修改權限", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If

            Me.DtpStartDate.Enabled = True
            Me.DtpEndDate.Enabled = True
            Me.BtnFind.Enabled = True

            MainFrom.ToolStripAdd.Enabled = False
            MainFrom.ToolStripSave.Enabled = True
            MainFrom.ToolStripEdit.Enabled = False
            MainFrom.ToolStripCancel.Enabled = True
            MainFrom.ToolStripDelete.Enabled = False

        Catch ex As Exception

        End Try
    End Function

    Public Function ActionExport() As Boolean Implements IDServer.IDServer.IDServer.ActionExport

    End Function

    Public Function ActionFilter() As Boolean Implements IDServer.IDServer.IDServer.ActionFilter

    End Function

    Public Function ActionGoFirst() As Boolean Implements IDServer.IDServer.IDServer.ActionGoFirst

    End Function

    Public Function ActionGoLast() As Boolean Implements IDServer.IDServer.IDServer.ActionGoLast

    End Function

    Public Function ActionGoNext() As Boolean Implements IDServer.IDServer.IDServer.ActionGoNext

    End Function

    Public Function ActionGoPrevious() As Boolean Implements IDServer.IDServer.IDServer.ActionGoPrevious

    End Function

    Public Function ActionImport() As Boolean Implements IDServer.IDServer.IDServer.ActionImport

    End Function

    Public Function ActionInitialize() As Boolean Implements IDServer.IDServer.IDServer.ActionInitialize

    End Function

    Public Function ActionPrint() As Boolean Implements IDServer.IDServer.IDServer.ActionPrint

    End Function

    Public Function ActionSave() As Boolean Implements IDServer.IDServer.IDServer.ActionSave
        Try
            If ConditonToSave() = False Then
                MessageBox.Show("調度單號為空！", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If

            Dim Strsql As String = ""
            Dim RowCount As Integer
            Dim i As Integer
            Dim fTranArrangedBill As String = Me.TxtArrangedBill.Text.ToString.Trim
            Dim fTranArrangedBy As String = PubUserCode
            Dim fTranArrangedDate As String = ServerDate

            RowCount = Me.DGVTranArrangeDetail.Rows.Count
            If RowCount > 0 Then
                For i = 0 To RowCount - 2
                    If Me.DGVTranArrangeDetail.Rows(i).Cells("fNumArranged").Value = "" Then
                        MessageBox.Show("請安排運輸")
                        Exit Function
                    End If
                    If Me.DGVTranArrangeDetail.Rows(i).Cells("fTimeArranged").Value = "" Then
                        MessageBox.Show("請安排出發時間")
                        Exit Function
                    End If
                    If Me.DGVTranArrangeDetail.Rows(i).Cells("fID").Value = "" Then
                        MessageBox.Show("請安排駕駛員")
                        Exit Function
                    End If
                Next
                If IsExistBill() = False Then
                    Strsql = "insert into LO_TransportArrangedA ( fTranArrangedBill, fTranArrangedBy, fTranArrangedDate, fBillStatus ) values ('" & fTranArrangedBill & "','" & fTranArrangedBy & "','" & fTranArrangedDate & "','A');"
                End If
                For i = 0 To RowCount - 2
                    Dim fInstructions As String = Me.DGVTranArrangeDetail.Rows(i).Cells("fInstructions").Value
                    Dim fNumArranged As String = Me.DGVTranArrangeDetail.Rows(i).Cells("fNumArranged").Value
                    Dim fNameArranged As String = Me.DGVTranArrangeDetail.Rows(i).Cells("fNameArranged").Value
                    Dim fTimeArranged As String = Me.DGVTranArrangeDetail.Rows(i).Cells("fTimeArranged").Value
                    Dim fID As String = Me.DGVTranArrangeDetail.Rows(i).Cells("fID").Value
                    If IsExistInstructions(fInstructions) = False Then
                        Strsql = Strsql & "insert into LO_TransportArrangedB (fTranArrangedBill,fInstructions, fNumArranged, fNameArranged,fTimeArranged,fID) values ('" & fTranArrangedBill & "','" & fInstructions & "', '" & fNumArranged & "', '" & fNameArranged & "','" & fTimeArranged & "','" & fID & "');"
                    Else
                        Strsql = "update LO_TransportArrangedB set fNumArranged='" & fNumArranged & "',fTimeArranged='" & fTimeArranged & "',fID='" & fID & "' where fInstructions='" & fInstructions & "' and fTranArrangedBill='" & fTranArrangedBill & "'"
                    End If
                Next

                ReturnObject(Strsql)
                MessageBox.Show("保存成功", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Me.TxtArrangedBill.Text = ""
                Me.TxtArrangedBill.Enabled = False
                Me.DtpStartDate.Enabled = False
                Me.DtpEndDate.Enabled = False
                Me.BtnFind.Enabled = False
                MainFrom.ToolStripSave.Enabled = False
                MainFrom.ToolStripCancel.Enabled = False
                MainFrom.ToolStripAdd.Enabled = True

            End If

        Catch ex As Exception

        End Try
    End Function

    Public Function ActionSelect() As Boolean Implements IDServer.IDServer.IDServer.ActionSelect

    End Function

    Private Function IsExistBill() As Boolean
        Try
            Dim B As Boolean = True
            Dim Conditonsql As String
            Dim RST As New DataSet
            Conditonsql = "select * from dbo.LO_TransportArrangedB Where fTranArrangedBill='" & Me.TxtArrangedBill.Text.ToString.Trim & "'"
            RST = ReturnDataset(Conditonsql)
            If RST.Tables(0).Rows.Count > 0 Then
                B = True
            Else
                B = False
            End If
            Return B
        Catch ex As Exception

        End Try
    End Function

    Private Function IsExistInstructions(ByVal fInstructions As String) As Boolean
        Try
            Dim B As Boolean = True
            Dim Conditonsql As String
            Dim RST As New DataSet
            Conditonsql = "select * from dbo.LO_TransportArrangedB Where fTranArrangedBill='" & Me.TxtArrangedBill.Text.ToString.Trim & "' and fInstructions='" & fInstructions & "'"
            RST = ReturnDataset(Conditonsql)
            If RST.Tables(0).Rows.Count > 0 Then
                B = True
            Else
                B = False
            End If
            Return B
        Catch ex As Exception

        End Try
    End Function

#End Region


End Class
